<?php
namespace app\index\controller;
use think\Controller;
use app\common\model\UserInfo;
use app\common\model\Notice;

class Index extends IndexBase
{
    public function index()
    {
        $notice = new Notice;
        $noticeList = $notice->getnotice();
        $this->assign('noticeList', $noticeList);

         return $this->fetch();
    }

    public function login()
    {
          return $this->fetch();
    }

    public function register(){
        return $this->fetch();
    }
    public function introduce(){
        $id = input('id');
        $notice = new Notice;
        $_opt['id'] = $id;
        $noticeinfo = $notice->getNoticeInfo($_opt);
        $this->assign('noticeinfo', $noticeinfo);
        return $this->fetch();
    }
    public function checklogin(){
        $post = input('post.');
        $UserInfo = new UserInfo;
        $_opt['user_name'] = $post['user_name'];
        $Info = $UserInfo->getUserInfo($_opt);
        if(!$Info){
            $this->error('用户不存在！');
        }
        $psd  = strtoupper(sha1(trim(input('post.user_password'))));

        if($psd === $Info['user_password']){
            session('user_name',$post['user_name']);
            session('user_login_date',date("Y-m-d H:i:s"));
            $this->success('登入成功','index/index');
        }else{
             $this->error('账号或密码错误！');
        }
    }
    /**
     * 验证注册
     * [checkreg description]
     * @return [type] [description]
     */
    public function checkreg(){
        $User = new UserInfo;
        $_opt['user_name'] = input('post.user_name');
        $_opt['user_password'] = strtoupper(sha1(trim(input('post.user_password'))));
        $_opt['user_mobile'] = trim(input('post.user_mobile'));
        $_opt['create_time'] = time();
        $adduser = $User->addUserInfo($_opt);
        if($adduser){
             $this->success('注册成功','index/login');
        }else{
            $this->error($User->getError());
        }

    }
   
   //public function 
}
